package com.liran.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.liran.entity.VipInfoEntity;
import com.liran.mapper.VipInfoMapper;
import com.liran.param.VipInfoListParam;
import com.liran.service.VipInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author whh
 * @since 2022-07-10
 */
@Service
public class VipInfoServiceImpl extends ServiceImpl<VipInfoMapper, VipInfoEntity> implements VipInfoService {

    @Autowired
    private VipInfoMapper vipInfoMapper;

    @Override
    public Page<VipInfoEntity> listSearch(VipInfoListParam vipInfoListParam) {
        QueryWrapper<VipInfoEntity> queryWrapper = new QueryWrapper<>();
        conditionHandle(vipInfoListParam, queryWrapper);
        Page<VipInfoEntity> page = new Page<>(vipInfoListParam.getPage(), vipInfoListParam.getLimit());
        vipInfoMapper.selectPage(page, queryWrapper);
        return page;
    }

    private void conditionHandle(VipInfoListParam vipInfoListParam, QueryWrapper<VipInfoEntity> queryWrapper) {
        if (StrUtil.isNotEmpty(vipInfoListParam.getName())) {
            queryWrapper.eq("name", vipInfoListParam.getName());
        }
        if (StrUtil.isNotEmpty(vipInfoListParam.getPhone())) {
            queryWrapper.eq("phone", vipInfoListParam.getPhone());
        }
        if (vipInfoListParam.getType() != null) {
            queryWrapper.eq("type", vipInfoListParam.getType());
        }
    }

}
